package com.ruoyi.system.controller;

import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.Difficult;
import com.ruoyi.system.service.DifficultService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: zhang
 * @Date: 2023/02/19/10:01
 * @Description: 培训教育 难度管理
 */
@RestController
@RequestMapping("/difficult")
public class SysTestDifficultController extends BaseController {
    @Autowired
    private DifficultService service;

    @GetMapping("/list")
    @RequiresPermissions("difficult:list")
    public TableDataInfo list(Difficult difficult) {
        startPage();
        List<Difficult> difficults = service.queryDifficults(difficult);
        return getDataTable(difficults);
    }

    @PostMapping("/save")
    @Log(title = "难度管理", businessType = BusinessType.INSERT)
    public AjaxResult save(@RequestBody Difficult difficult) {
        boolean b = service.saveOrUpdate(difficult);
        return AjaxResult.success(b);
    }

    @DeleteMapping("/delete/{id}")
    @Log(title = "难度管理", businessType = BusinessType.DELETE)
    public AjaxResult delete(@PathVariable Integer id) {
        boolean b = service.removeById(id);
        return AjaxResult.success(b);
    }

    @DeleteMapping("/deletes/{ids}")
    @Log(title = "难度管理", businessType = BusinessType.DELETE)
    public AjaxResult deletes(@PathVariable Integer[] ids) {
        boolean b = service.removeByIds(ids);
        return AjaxResult.success(b);
    }

    @GetMapping("/info/{id}")
    public AjaxResult info(@PathVariable Integer id) {
        Difficult difficult = service.queryById(id);
        return AjaxResult.success(difficult);
    }
}